use periph_utils::GpioConfig;
use periph_utils::stm32f1;

use crate::cp_door::DoorErr;

use super::sensor;


#[derive(GpioConfig)]
#[gpio(init = "gpio_init",
    io(name = "led1", io = "PB0", mode = "OUT_PP", set, reset),
    io(name = "led2", io = "PB9", mode = "OUT_PP", set, reset),
    io(name = "e", io = "PB10", mode = "OUT_PP", set, reset),
)]
struct Pin;

pub unsafe fn init() {
    Pin::gpio_init();
}

pub fn led1_open() {
    Pin::led1_set();
}

pub fn led1_close() {
    Pin::led1_reset();
}

pub fn led2_open() {
    Pin::led2_set();
}

pub fn led2_close() {
    Pin::led2_reset();
}

pub fn straw_open() {
    Pin::e_set();
}

pub fn straw_close() -> Result<(), DoorErr> {
    if !sensor::is_straw_close() {
        return Err(DoorErr::StrawCloseFail);
    }
    Pin::e_reset();

    Ok(())
}

pub fn straw_force_close() {
    Pin::e_reset();
}





